#### Start of system configuration section. ####

srcdir =	@srcdir@
VPATH =		@srcdir@

# Common prefix for machine-independent installed files.
prefix =	@prefix@

# Common prefix for machine-dependent installed files.
exec_prefix =	@exec_prefix@

bindir =	$(exec_prefix)/bin
libdir =	$(exec_prefix)/Sys/libs

INSTALL =	@INSTALL@
INSTALL_DATA =	@INSTALL_DATA@

CC =		@CC@

CFLAGS =	@CFLAGS@
LDFLAGS =	@LDFLAGS@

RANLIB =	@RANLIB@
AR =		ar
RM =		rm -f

#### End system configuration section ####

# For now we only build one CPU/FPU flavor of libc.a, which is the most generic version.

CPUDIR		= 68000
FPUDIR		= soft-float

FLAVOR_CFLAGS =
OTHER_CFLAGS =	-fomit-frame-pointer
ALL_CFLAGS =	$(CFLAGS) $(FLAVOR_CFLAGS) $(OTHER_CFLAGS) $(INCS) $(DEFS)

DEFS =
INCS =		-I$(srcdir) -I$(srcdir)/../library -I$(srcdir)/../include
SHELL =		/bin/sh

.c.o:
		$(CC) $(ALL_CFLAGS) -c $< -o $@

.s.o:
		cp $*.s x.c
		$(CC) $(CFLAGS) $(OTHER_CFLAGS) -traditional -E x.c -o x.s
		$(CC) $(CFLAGS) $(OTHER_CFLAGS) $(INCS) -c x.s -o $*.o
		$(RM) x.c x.s


SRC =		__panic.c v1.c v2.c v3.c v4.c v5.c v6.c v7.c v8.c v9.c v10.c

OBJ =		$(SRC:.c=.o)

all:		libcrt.a libc.a libc_p.a libbc.a crt0.o bcrt0.o rcrt0.o mcrt0.o gcrt0.o

crt0.o:		crt0.c ../library/version.h
		$(CC) $(CFLAGS) $(OTHER_CFLAGS) $(INCS) -c -DCRT0 $< -o $@

bcrt0.o:	crt0.c ../library/version.h
		$(CC) $(CFLAGS) $(OTHER_CFLAGS) -fbaserel -DBASECRT0 $(INCS) -c $< -o $@

rcrt0.o:	crt0.c ../library/version.h
		$(CC) $(CFLAGS) $(OTHER_CFLAGS) -fbaserel -DBASECRT0 -DRCRT0 $(INCS) -c $< -o $@

mcrt0.o:	crt0.c ../library/version.h gmon.c gmon.h
		$(CC) $(CFLAGS) $(OTHER_CFLAGS) $(INCS) -c -DMCRT0 -fno-omit-frame-pointer $< -o $@

gcrt0.o:	mcrt0.o
		cp $< $@

libcrt.a:	$(OBJ)
		$(RM) libcrt.a
		$(AR) qc libcrt.a $(OBJ)

libc.a:		libcrt.a ../glue/no-baserel/libglue.a ../static/no-baserel/$(CPUDIR)/$(FPUDIR)/libstatic.a \
		../stack/no-baserel/$(CPUDIR)/$(FPUDIR)/libstack.a #../network/no-baserel/$(CPUDIR)/$(FPUDIR)/libnet.a
		$(RM) $@
		$(RM) -r tempobj
		mkdir tempobj
		(cd tempobj; $(AR) x ../libcrt.a)
		(cd tempobj; $(AR) x ../../glue/no-baserel/libglue.a)
		(cd tempobj; $(AR) x ../../static/no-baserel/$(CPUDIR)/$(FPUDIR)/libstatic.a)
		(cd tempobj; $(AR) x ../../stack/no-baserel/$(CPUDIR)/$(FPUDIR)/libstack.a)
#		(cd tempobj; $(AR) x ../../network/no-baserel/$(CPUDIR)/$(FPUDIR)/libnet.a)
		(cd tempobj; $(AR) rv ../$@ *.o)
		$(RANLIB) $@
		$(RM) -r tempobj

libc_p.a:	libcrt.a ../glue/no-baserel/libglue_p.a ../static/no-baserel/$(CPUDIR)/$(FPUDIR)/libstatic.a \
		../stack/no-baserel/$(CPUDIR)/$(FPUDIR)/libstack.a #../network/no-baserel/$(CPUDIR)/$(FPUDIR)/libnet.a
		$(RM) $@
		$(RM) -r tempobj
		mkdir tempobj
		(cd tempobj; $(AR) x ../libcrt.a)
		(cd tempobj; $(AR) x ../../glue/no-baserel/libglue_p.a)
		(cd tempobj; $(AR) x ../../static/no-baserel/$(CPUDIR)/$(FPUDIR)/libstatic.a)
		(cd tempobj; $(AR) x ../../stack/no-baserel/$(CPUDIR)/$(FPUDIR)/libstack.a)
#		(cd tempobj; $(AR) x ../../network/no-baserel/$(CPUDIR)/$(FPUDIR)/libnet.a)
		(cd tempobj; $(AR) rv ../$@ *.o)
		$(RANLIB) $@
		$(RM) -r tempobj

libbc.a:	libcrt.a ../glue/baserel/libglue.a ../static/baserel/$(CPUDIR)/$(FPUDIR)/libstatic.a \
		../stack/baserel/$(CPUDIR)/$(FPUDIR)/libstack.a #../network/baserel/$(CPUDIR)/$(FPUDIR)/libnet.a
		$(RM) $@
		$(RM) -r tempobj
		mkdir tempobj
		(cd tempobj; $(AR) x ../libcrt.a)
		(cd tempobj; $(AR) x ../../glue/baserel/libglue.a)
		(cd tempobj; $(AR) x ../../static/baserel/$(CPUDIR)/$(FPUDIR)/libstatic.a)
		(cd tempobj; $(AR) x ../../stack/baserel/$(CPUDIR)/$(FPUDIR)/libstack.a)
#		(cd tempobj; $(AR) x ../../network/baserel/$(CPUDIR)/$(FPUDIR)/libnet.a)
		(cd tempobj; $(AR) rv ../$@ *.o)
		$(RANLIB) $@
		$(RM) -r tempobj

../library/version.h:	../library/parse_version.c ../version.in
		gcc -o parse_version $<
		parse_version ../library
		rm -f parse_version

clean:
		rm -rf tempobj *.[oa]

clobber:	clean
		rm -f Makefile
